﻿using MB.Orm.DB;
using MB.RuleBase.Common;
using Model;
using Public.DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Service
{
    public class BLocationGoods
    {
        public BLocationGoods() { }

        /// <summary>
        /// 查询货位商品关联
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="total"></param>
        /// <param name="parValues"></param>
        /// <returns></returns>
        public List<LocationGoods> GetLocationGoodsList(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<LocationGoods> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<LocationGoods>
                                                ("LocationGoods", "GetLocationGoodsInfo", pageIndex, pageSize, out total, parValues);
                return list;
            }
        }


        /// <summary>
        /// 查询货位库存
        /// </summary>
        /// <param name="locationCode"></param>
        /// <returns></returns>
        public LocationInventoryInfo CheckLocation(string locationId, string goodsId)
        {
            LocationInventoryInfo Info = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<LocationInventoryInfo>("LocationGoods", "CheckLocationInventory", locationId, goodsId).FirstOrDefault();
            return Info;
        }

        /// <summary>
        /// 查询货位上此商品是否有库存
        /// </summary>
        /// <param name="locationCode"></param>
        /// <returns></returns>
        public List<Goods> CheckLocation(string goodsCode)
        {
            List<Goods> Info = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<Goods>("LocationGoods", "CheckLocationInventory", goodsCode);
            return Info;
        }


        /// <summary>
        /// 修改商品状态
        /// </summary>
        /// <param name="locationGoodsID"></param>
        /// <returns></returns>
        public int UpdateLocationGoods(LocationGoods locationGoods)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQueryByEntity<LocationGoods>("LocationGoods", "UpdateLocationGoods", locationGoods);
        }

        /// <summary>
        /// 新增货位商品关联
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public int AddLocationGoods(LocationGoods location)
        {
                return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQueryByEntity<LocationGoods>("LocationGoods", "AddLocationGoods", location);
        }


        /// <summary>
        /// 查询商品是否存在
        /// </summary>
        /// <param name="locationCode"></param>
        /// <returns></returns>
        public List<Goods> CheckGoodsInfo(string goodsCode)
        {
            List<Goods> Info = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<Goods>("LocationGoods", "CheckGoods", goodsCode);
            return Info;
        }


        /// <summary>
        /// 检查商品是否绑定过库位
        /// </summary>
        /// <param name="IsSetAll"></param>
        /// <returns></returns>
        public List<LocationGoods> GetLocationGoodsInfo(string where)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<LocationGoods> lstLocation = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml4<LocationGoods>("LocationGoods", "CheckLocationGoodsInfo", where);
  
                return lstLocation;
            }
        }

    }
}
